﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Core.Extensions;
using VOL.Entity.DomainModels;
using VOL.Entity.DomainModels.DoctorManage;
using VOL.Entity.DomainModels.EvaluateNurseCare;
using VOL.SmartMecial.Dtos;
using VOL.SmartMecial.Infrastructure;
using VOL.SmartMecial.IServices.EvaluateNurseCare;

namespace VOL.SmartMecial.Services.EvaluateNurseCare
{
    public class TellService:ITellService
    {
        private readonly IBaseRepository<TellModel> _tellRepo;

        private readonly IBaseRepository<Patient> _patientRepo;

        private readonly IBaseRepository<DoctorModel> _doctorRepo;

        private readonly IBaseRepository<Bed> _bedRepo;

        public TellService(IBaseRepository<TellModel> tellRepo, IBaseRepository<Patient> patientRepo, IBaseRepository<Bed> bedRepo, IBaseRepository<DoctorModel> doctorRepo)
        {
            _tellRepo = tellRepo;
            _patientRepo = patientRepo;
            _bedRepo = bedRepo;
            _doctorRepo = doctorRepo;
        }

        public async Task<List<TellDTO>> GetTell(string? DoctorName)
        {
            var tellList = from tell in _tellRepo.GetAll()
                           join patient in _patientRepo.GetAll() on tell.PatientCode equals patient.PatientCode
                           where tell.IsDelete ==0&&tell.IsPublisher==1
                           select new TellDTO
                           {
                               Id = tell.Id,
                               BedCode = tell.BedCode,
                               DoctorCode = tell.DoctorCode,
                               DoctorName = tell.DoctorCode,
                               PatientCode = tell.PatientCode,
                               Name = patient.Name,
                               DoctorContent = tell.DoctorContent,
                               DoctorSTime = tell.DoctorSTime,
                               DoctorETime = tell.DoctorETime,
                               IsPublisher = tell.IsPublisher,
                               IsDelete = tell.IsDelete
                           };
            tellList = tellList.WhereIF(!string.IsNullOrEmpty(DoctorName), x => x.DoctorCode.Contains(DoctorName));


            return await Task.FromResult(tellList.ToList());
        }
    }
}
